import 'package:flutter/material.dart';

class KeepAliveWrapper extends StatefulWidget {

  final Widget child;
  final bool keepAlive;

  const KeepAliveWrapper({super.key, required this.child, this.keepAlive=true});

  @override
  State<KeepAliveWrapper> createState() => _KeepAliveWrapperState();
}

class _KeepAliveWrapperState extends State<KeepAliveWrapper> with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    return widget.child;
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => widget.keepAlive;

  @override
  void didUpdateWidget(covariant KeepAliveWrapper oldWidget) {
    if(oldWidget.keepAlive !=widget.keepAlive) {
      updateKeepAlive();
    }
  }
}
